package cc.xsubj.engine;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;

import cc.xsubj.engine.entity.Entity;

public abstract class Camera
{

    protected World world;
    /** coordinates of the top left corner of the camera area in the world */
    public float cameraX;
    public float cameraY;
    protected Rectangle viewport = null;
    protected Rectangle bounds = null;
    protected Entity follow;
    /** width and height of the render area for this camera */
    protected float renderWidth;
    protected float renderHeight;

    public Camera(World world, Entity follow, int renderWidth, int renderHeight)
    {
        this.world = world;
        this.follow = follow;
        this.renderWidth = renderWidth;
        this.renderHeight = renderHeight;
        this.cameraX = 0;
        this.cameraY = 0;
        this.viewport = new Rectangle(0, 0, renderWidth, renderHeight);
        this.bounds = viewport;
    }

    public void update(GameContainer container, int delta) throws SlickException
    {
    	setCamera();
    }
    
    protected abstract void setCamera();

    public World getWorld()
    {
    	return world;
    }

    public void setWorld(World myWorld)
    {
    	this.world = myWorld;
    }

    public Entity getFollow()
    {
    	return follow;
    }

    public void setFollow(Entity follow)
    {
    	this.follow = follow;
    }

    public Rectangle getViewport()
    {
    	return viewport;
    }

    public Rectangle getBounds()
    {
    	return bounds;
    }

    public boolean contains(Entity e)
    {
    	Rectangle entity = new Rectangle(e.x, e.y, e.width, e.height);
    	return viewport.intersects(entity);
    }

}